<!--
 * @Author: lsy
 * @Date: 2023-02-14 19:55:19
 * @LastEditors: lsy
 * @LastEditTime: 2023-02-16 18:02:40
 * @Description: 毕业作品浏览
-->
<template>
  <sc-dialog
    v-model="visible"
  >
    <template #header>
      毕业作品浏览
    </template>
    <div class="file-list">
      <div class="file-item" v-for="(file, idx) in fileList" :key="idx">
        <div v-if="isImage(file.file)">
          <el-image :src="file.baseUrl || ''" fit="cover" :preview-src-list="[file.baseUrl]" />
        </div>
        <div v-else>
          <VideoPlay
            :src="file.baseUrl"
          />
        </div>
      </div>
    </div>
  </sc-dialog>
</template>

<script setup>
import { computed, defineProps, defineEmits } from 'vue';
import VideoPlay from './video-play.vue';

const props = defineProps({
  fileList: {
    type: Array,
    default: () => []
  },
  modelValue: {
    type: Boolean,
    default: false,
  }
})
const emits = defineEmits(['update:modelValue'])
const visible = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emits('update:modelValue', val)
  }
})

const isImage = file => /jpe?g|png|gif/.test(file.type)
</script>

<style lang="scss" scoped>
.file-list {
  display: flex;
  flex-wrap: wrap;
  .file-item {
    position: relative;
    width: 25%;
    padding-bottom: 15%;
    margin-bottom: 10px;
    padding-left: 10px;
    box-sizing: border-box;
    >div {
      position: absolute;
      left: 0;
      right: 15px;
      top: 0;
      bottom: 0;
      .el-image {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
    &:nth-child(3n) {
      margin-right: 0;
    }
  }
}
</style>